<?php
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

if (!JFactory::getUser()->authorise('core.manage', 'com_audience'))
{
	return JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR'));
}
if(!defined('DS')){
	define('DS',DIRECTORY_SEPARATOR);
}
date_default_timezone_set('Asia/Ho_Chi_Minh');
jimport('joomla.application.component.controller' );
jimport('joomla.form.form' );jimport('joomla.user.helper');
require_once( JPATH_COMPONENT_ADMINISTRATOR.DS.'helpers'.DS.'wrd.php');require_once( JPATH_COMPONENT_ADMINISTRATOR.DS.'classes'.DS.'utilities'.DS.'pointProvider.php');require_once( JPATH_COMPONENT_ADMINISTRATOR.DS.'classes'.DS.'utilities'.DS.'reportProvider.php');
require_once( JPATH_COMPONENT_ADMINISTRATOR.DS.'classes'.DS.'utilities'.DS.'utilitiesProvider.php');

// set tables directory
JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR.DS.'tables');
JHTML::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR.DS.'html');
JLoader::register('LanguagesModelInstalled', JPATH_ADMINISTRATOR.DS.'components'.DS.'com_languages'.DS.'models'.DS.'installed.php');
JLoader::register('WrdLog', JPATH_COMPONENT_ADMINISTRATOR.DS.'classes'.DS.'log.php');
JLoader::register('WrdView', JPATH_COMPONENT_ADMINISTRATOR.DS.'classes'.DS.'view.php');
JLoader::register('WrdModel', JPATH_COMPONENT_ADMINISTRATOR.DS.'classes'.DS.'model.php');
// include proper controller class
$controllerName = JRequest::getCmd('controller');

// Auto detect if the controller name is same view name, use this controller
if ($controllerName == '') {
	$view = JRequest::getCmd('view');
	if ($view && file_exists(JPATH_COMPONENT_ADMINISTRATOR.DS.'controllers'.DS.strtolower($view).'.php'))
		$controllerName = $view;
	else{
		$task = JRequest::getVar('task');
		$task_arr = explode('.', $task);
		if(count($task_arr) == 2){
			$controllerName = $task_arr[0];
			$first_task = $task_arr[1];
		}
		else{
			$first_task = $task_arr[0];
		}
	}
}                     

$path = $controllerName ? JPATH_COMPONENT_ADMINISTRATOR.DS.'controllers'.DS.strtolower($controllerName).'.php' : JPATH_COMPONENT_ADMINISTRATOR.DS.'controller.php';
if (!file_exists($path)) $path = JPATH_COMPONENT_ADMINISTRATOR.DS.'controller.php';
require_once $path;
// create controller
$className = "WrdController$controllerName";
$controller = new $className();
// execute action
$task = str_replace($controllerName.'.', '', JRequest::getCmd('task')); 
$controller->execute($task);

// redirecting
$controller->redirect();